#include "Fan.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "GameplayState.h"
#include "Game.h"

Fan::Fan()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();
	m_hImage = pGraphics->LoadTexture("resource/graphics/FanAnimation.png", SGD::Color(255, 255, 255, 255));

}


Fan::~Fan()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();
	pGraphics->UnloadTexture(m_hImage);
}

void Fan::Update(float dt)
{
	m_unFrame++;
	if (m_unFrame > 1)
		m_unFrame = 0;
}


void Fan::Render()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();
	int x = GameplayState::GetInstance()->GetCamX();
	int y = GameplayState::GetInstance()->GetCamY();

	SGD::Point camera = { m_ptPosition.x - x, m_ptPosition.y - y };

	if (camera.x + m_szSize.width < 0
		|| camera.x - m_szSize.width  > Game::GetInstance()->GetScreenWidth()
		|| camera.y + m_szSize.height  < 0
		|| camera.y - m_szSize.height  > Game::GetInstance()->GetScreenHeight())
		return;

	pGraphics->DrawTextureSection(m_hImage, camera, SGD::Rectangle(122.0f * m_unFrame, 18.0f, 122.0f * (m_unFrame + 1), 200.0f), { 0.0f }, {}, {}, { .75f, .75f });

}
